package com.digoyo.hr.exception;

import com.digoyo.hr.model.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @Author: Daniel
 * @Description:
 * @Date: Created in 4:08 PM 2020/6/11
 * @Modified By:
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(SQLException.class)
    public RespBean SQLException(SQLException e){
        e.printStackTrace();
        if (e instanceof SQLIntegrityConstraintViolationException) {
            return RespBean.error("该数据有关联数据,操作失败");
        }
        return RespBean.error("数据库异常,操作失败");
    }
}
